#include "Artillery.h"
#include "Box.h"
#include "RSManager.h"
#include "Sprite.h"
#include "ShareComponents.h"
#include "MainGame.h"

Artillery::Artillery(Box* box) : Object(box, Obj_DYNAMID), MoveObject()
{
	_sprite = RSManager::getInstance()->getSprite(ARTILLERY);
	delay = 0;
	_initBox = new Box(box->_position, box->_size, box->_v);
	_isAlive = true;
	_box->_size -= _box->_size/2;
	_box->_position += _box->_size/2;
	_colBox->_position = gl_BOX_0_0_0->_position;
	_colBox->_size = gl_BOX_0_0_0->_size;
	_colBox->_v = gl_BOX_0_0_0->_v;
	AssignMove(_box);
}


Artillery::~Artillery(void)
{
}

void Artillery::update()
{
	delay += GAME_TIME;
	if (delay >= 300)
	{
		delay = 0;
		_sprite->Next();
	}
	_box->_v.y -= g / 2.50f;
	if(!moveDiagonalThrowCollide2(30))
	{
		_isAlive = false;	
		Artillery* art = new Artillery(_initBox);
		gl_MainGame->addWorldObject(art);
	}
}

void Artillery::render()
{
	_sprite->Render(_box->_position);
}

Box* Artillery::getCollisionBox()
{
	return _colBox;
}
